layui.use(['form', 'admin', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload; //得到 upload 对象

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    
    //选完文件后不自动上传
    $('#test9').click(function () {
		var  index = layer.msg('Processing file... Please wait', {
		  icon: 16,
		  shade: [0.2,'#000'], //0.1透明度的白色背景
		  time: false
	});
    	var formdata = new FormData();
    	formdata.append('file', document.getElementById("test8").files[0]);
    	formdata.append('operateId', $("#operateId").val());
    	formdata.append('customerId', $("#customerId").val());
    	formdata.append('setUnitId', $("#setUnitId").val());
    	$.ajax({
    		type: 'Post',
    		data:formdata,
    		cache: false,//上传文件无需缓存
    		processData:false, //告诉jQuery不要去处理发送的数据
    		contentType:false,
        	url: Feng.ctxPath + "/orderTransport/importExce",
    		success: function (data) {
        		layer.close(index);
        		if(data.success){
        			if (data.message != null &&data.message != "" ) {
        				var msg =  layer.open({
        					  title: 'Information' ,
        					  content: data.message,
        					  btn: ['OK'],
        					  yes: function (){
        						  	layer.close(msg);
        		                	var Indexs = parent.layer.getFrameIndex(window.name);
        		                    parent.layer.close(Indexs);
        					  }
        				});     
					} else {
	                    Feng.success("Import successful!"+data.message);
	                	var Indexs = parent.layer.getFrameIndex(window.name);
	                    parent.layer.close(Indexs);
					}
        		}else{
        			if (data.message !=null &&data.message!='') {
        				var msg =  layer.open({
    	  					  title: 'Information' ,
    	  					  content: data.message,
    	  					  btn: ['OK'],
    	  					  yes: function (){
    	  						  	layer.close(msg);
    	  					  }
        				});    
					} else {
		                    Feng.error("Import failed!");
					} 
        		}
    		},
        	error: function(data){
        		layer.close(index);
                Feng.error("Network error, please try again later!" + data.responseJSON.message)
          }
    	});
    });

    $(".a-upload").on("change","input[type='file']",function(){
        $(".showFileName").html("");
        var filePath=$(this).val();
        if(filePath.indexOf("xls")!=-1 || filePath.indexOf("xlsx")!=-1){
            var arr=filePath.split('\\');
            var fileName=arr[arr.length-1];
            $(".showFileName").html(fileName);
        }else{
            $(".showFileName").html("No file uploaded, or file type is incorrect!");
            return false 
        }
    })
    
    //返回按钮
    $("#backupPage").click(function () {
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });

});